package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsComputeStatistics;
import com.econ.powercloud.ems.dal.mapper.EmsComputeStatisticsMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

/**
 * @ Description:
 * @ Author：hgp
 * @ Create:2022-11-29-10:10
 */
@Repository
public class EmsComputeStatisticsDAO extends ServiceImpl<EmsComputeStatisticsMapper, EmsComputeStatistics> {
    private static final String LIMIT_ONE = "limit 1";

    public EmsComputeStatistics selectOneByCondition(String energyStationId, String computeModel) {
        LambdaQueryWrapper<EmsComputeStatistics> wrapper = Wrappers.<EmsComputeStatistics>lambdaQuery()
                .eq(EmsComputeStatistics::getEnergyStationId, energyStationId)
                .eq(EmsComputeStatistics::getComputeModel, computeModel)
                .orderByDesc(EmsComputeStatistics::getId)
                .last(LIMIT_ONE);
        return this.getBaseMapper().selectOne(wrapper);
    }
}
